﻿using System.Data;
using System.Configuration;
using System.Data.SqlClient;

namespace DHAA.Default.App_Code
{
    /// <summary>
    /// Summary description for AccessData
    /// </summary>
    public class AccessData
    {
        private static string ConnectString = ConfigurationManager.ConnectionStrings["connectDHAA"].ConnectionString;
        public SqlConnection GetConnect()
        {
            return new SqlConnection(ConnectString);
        }
        public DataTable GetTable(string sql)
        {
            SqlConnection conn = GetConnect();
            if (conn.State == ConnectionState.Closed)
            {
                conn.Open();
            }
            SqlDataAdapter adap = new SqlDataAdapter(sql,conn);
            DataTable dt = new DataTable();
            adap.Fill(dt);
            conn.Close();
            return dt;
        }
        public void ExeCuteQuery(string sql)
        {
            SqlConnection conn = GetConnect();
            if (conn.State == ConnectionState.Closed)
            {
                conn.Open();
            }
            SqlCommand cmd = new SqlCommand(sql, conn);
            cmd.ExecuteNonQuery();
            conn.Close();
        }
        public SqlDataReader ExecuteReader(string sql)
        {
            SqlConnection conn = GetConnect();
            if (conn.State == ConnectionState.Closed)
            {
                conn.Open();
            }
            SqlCommand cmd = new SqlCommand(sql, conn);
            SqlDataReader dr = cmd.ExecuteReader();
            return dr;
        }
    }
}
